import type { PageList, ResponseStruct } from '#/global'
import { UserVo } from '@/modules/base/api/user';
import { QuestionGroupVo } from './group';
export type QuestionType = 'choice' | 'fill' | 'translate' | 'connect' | 'oral_interpretation';
export interface QuestionVo {
  id?: number;
  type?: QuestionType;
  group?: QuestionGroupVo;
  group_id?: number;
  level?: number;
  answers?: any[];
  analysis?: string;
  created_at?: string;
  updated_at?: string;
  creator_id?: number;
  creator?: UserVo
}

export interface QuestionSearchVo {
  type?: QuestionType;
  group?: QuestionGroupVo;
  group_id?: number;
  level?: number;
  page_size?:number;
  page?:number;
}

export function page(data: QuestionSearchVo): Promise<ResponseStruct<PageList<QuestionVo>>> {
  return useHttp().get('/admin/question', { params: data })
}

export function create(data: QuestionVo): Promise<ResponseStruct<null>> {
  return useHttp().post('/admin/question', data)
}

export function save(id: number, data: QuestionVo): Promise<ResponseStruct<null>> {
  return useHttp().put(`/admin/question/${id}`, data)
}

export function deleteByIds(ids: number[]): Promise<ResponseStruct<null>> {
  return useHttp().delete('/admin/question', { data: ids })
}

export const levels = [
  {
    name: '简单',
    level: 1,
    color: 'pink',
  },
  {
    name: '一般',
    level: 2,
    color: 'blue'
  },
  {
    name: '困难',
    level: 3,
    color: 'yellow'
  },
];
export const question_types = [
  {
    name: '选择题',
    code: 'choice',
    item_name: '选项'
  },
  {
    name: '填空题',
    code: 'fill',
    item_name: '空位'
  },
  {
    name: '翻译题',
    code: 'translate',
    item_name: '答案'
  },
  {
    name: '连线题',
    code: 'connect',
    item_name: '答案'
  },
  {
    name: '口译题',
    code: 'oral_interpretation',
    item_name: '答案'
  },
]
